package hw.ats.news.ui;

import hw.ats.news.R;
import hw.ats.news.activity.etc.MoreAct;
import hw.ats.news.activity.news.BookmarkAct;
import hw.ats.news.activity.news.MovieAct;
import hw.ats.news.activity.news.PhotoAct;
import hw.ats.news.activity.news.RecentAct;
import hw.ats.news.activity.news.RecmdAct;
import android.app.Activity;
import android.content.Intent;

import com.humanwares.ui.tabbar.Tab;
import com.humanwares.ui.tabbar.TabHost;
import com.humanwares.ui.tabbar.TabHostProvider;
import com.humanwares.ui.tabbar.TabViewConfig;
import com.tattermedia.allthataudio.activities.PlayListActivity;

public class BottomTabHostProvider extends TabHostProvider {
	public static final int NONE = 0;
	public static final int TAB1 = 1;
	public static final int TAB2 = 2;
	public static final int TAB3 = 3;
	
	// fix more tab bug
	public static final int TAB4 = 5;
	public static final int TAB5 = 4;

	private TabHost tabHost = null;

	public BottomTabHostProvider(Activity context) {
		super(context);
	}

	@Override
	public TabHost getTabHost(int tab) {
		tabHost = new TabHost(new TabViewConfig().context(context)
				.headerResourceId(R.drawable.tabbar_bg).separatorId(
						R.drawable.tabbar_separator).margin(7, 0, 7, 0));

		Intent intent = null;
		boolean tabSelects[] = new boolean[5];
		for (int i = 0, len = tabSelects.length; i < len; i++) {
			tabSelects[i] = false;
		}

		// 최신글 탭
		Tab tab1 = null;

		// 플레이 리스트 탭
		Tab tab2 = null;

		// 즐겨찾기 탭
		Tab tab3 = null;

		// 동영상 탭
//		Tab tab4 = null;

		// 더보기 탭
		Tab tab5 = null;
		

		// 최신글
		intent = new Intent(context, RecentAct.class);
		intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		tab1 = new Tab(context, "RECENT");
		tab1.setIcon(R.drawable.tabbar_tab1);
		tab1.setIconSelected(R.drawable.tabbar_tab1_selected);
		tab1.setIntent(intent);
		tabHost.addTab(tab1);

		// 플레이 리스트
		intent = new Intent(context, PlayListActivity.class);
		intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
		tab2 = new Tab(context, "PLAYLIST");
		tab2.setIcon(R.drawable.tabbar_tab2);
		tab2.setIconSelected(R.drawable.tabbar_tab2_selected);
		tab2.setIntent(intent);
		tabHost.addTab(tab2);

		// 즐겨찾기
		intent = new Intent(context, BookmarkAct.class);
		intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
		tab3 = new Tab(context, "FAVRITE");
		tab3.setIcon(R.drawable.tabbar_tab3);
		tab3.setIconSelected(R.drawable.tabbar_tab3_selected);
		tab3.setIntent(intent);
		tabHost.addTab(tab3);

		// 동영상

//Tab tab4 = null;
//intent = new Intent(context, MovieAct.class);
//intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//tab4 = new Tab(context, "MOVIE");
//tab4.setIcon(R.drawable.tabbar_tab4);
//tab4.setIconSelected(R.drawable.tabbar_tab4_selected);
//tab4.setIntent(intent);
//tabHost.addTab(tab4);


		// 더보기
		intent = new Intent(context, MoreAct.class);
		intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
		tab5 = new Tab(context, "MORE");
		tab5.setIcon(R.drawable.tabbar_tab5);
		tab5.setIconSelected(R.drawable.tabbar_tab5_selected);
		tab5.setIntent(intent);
		tabHost.addTab(tab5);

		if (tab > 0)
			tabSelects[tab - 1] = true;
		tab1.setSelected(tabSelects[0]);
		tab2.setSelected(tabSelects[1]);
		tab3.setSelected(tabSelects[2]);
//		tab4.setSelected(tabSelects[3]);
		tab5.setSelected(tabSelects[3]);

		return tabHost;
	}
}
